﻿using AppSocketModel;
using BCGPSCommon;
using BCGPSMongoData;
using System;
using System.Collections.Generic;
using System.Text;

namespace AppSocketControl.GpsData.DataDispatch
{
    public class DispatchRealDataCmdReturn
    {
        private readonly MongoDBCommand<RealSendDataDto> mongoDBCommand;
        private RealSendDataDto realSendData = new RealSendDataDto();
        private readonly IRedisService redisService;
        public DispatchRealDataCmdReturn()
        {
            redisService = new RedisService();
            mongoDBCommand = new MongoDBCommand<RealSendDataDto>("RealSendDataHistory");
        }

        private void Split(string[] dataArr)
        {
            realSendData.IMEI = dataArr[5];

            realSendData.CmdDateTime = MongoDBDateTime.GetNowUtc();
            realSendData.CmdToward = "Receive";
            realSendData.CmdCode = ((int)GpsCmdCode.SendTimeSpanReal).ToString();
            realSendData.Result = dataArr[7];

        }
        /// <summary>
        /// 设备运行状态数据写入数据库
        /// </summary>
        /// <param name="dataArr"></param>
        public void Run(string[] dataArr)
        {
            Split(dataArr);
            mongoDBCommand.InsertDocumentAsync(realSendData).GetAwaiter().GetResult();
            redisService.AddAsync(GeneralContainer.RedisNameSpaceIMEISendCmd + realSendData.IMEI, string.Empty).GetAwaiter().GetResult();
        }
    }
}
